package com.zqc.controller;

import com.zqc.common.lang.Result;
import com.zqc.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Component
@RequestMapping("/test")
public class TestController {
    @Autowired
    private SysUserService userService;

    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;


    @PreAuthorize("hasRole('admin')")
    @GetMapping
    public Result test() {
        return Result.succ(userService.list());
    }

    // 测试密码加密后的结果
    @GetMapping("/pass")
    public Result pass() {
        String password = bCryptPasswordEncoder.encode("6666");
        System.out.println(password);
        boolean matches = bCryptPasswordEncoder.matches("6666", "$2a$10$Ngt6IBq75dn9iuyHsWxRbObu95Poo.OfgqJcnZrWFwfrr2qE/M1cu");
        System.out.println(matches);
        return Result.succ(password);
    }
}
